import re
import sys

# “/”：表示根目录，在windows系统下表示某个盘的根目录，如“E:\”；
# “./”：表示当前目录；（表示当前目录时，也可以去掉“./”，直接写文件名或者下级目录）
# “../”：表示上级目录。
sys.path.append("./decideChild")
import OnlyOne, RayElectricity, PePvcTube, JJX, Welding, Well, RepairRoad

"""该类处理1条信息"""


class Decide:
    def __init__(self, inse):
        self.inse = inse
        self.unit = self.theUnit()
        self.message = {}

    """该部分获取长度"""

    def theUnit(self):
        # try:
        xx = re.findall("\d*米$|一只|一套|\d*个$|\d*根$|\d*只$|\d*套$|\d*台$|\d*芯$|\d*D$|\d*平方米$|\d*平米$|\d*卷$|\d*次$", self.inse)[
            0]
        yy = re.split("米|只|个|根|套|台|芯|平方米|平米|D|卷|次", xx)[0]
        if yy == "一":
            return 1
        else:
            return int(yy)

    # except:
    #     return "no"

    """第一分类"""

    def select(self):
        # try:
        sel = re.findall(
            "使用|整理|线路整理|回抽|电源线|接地|地锚|电池|光缆|电缆|钢绞线|钢缆|电杆|井|子管|pe管|PE管子|pvc管|PVC管|钢管|出土管|路面|绿化|人行道|熔接|台班|用车|用工|分线|分纤|交接箱|光站|放大器|分支|分配|缆桥|光机|电源箱",
            self.inse)[0]
        if sel in ("使用"):
            return "material"
        elif sel in ("整理", "线路整理", "回抽", "接地", "地锚", "电池"):
            return OnlyOne.OnlyOne(sel).getOnelyOne()
        elif sel in ("光缆", "电缆", "钢绞线", "电杆", "钢缆", "电源线"):
            return RayElectricity.RayElectricity(sel, self.inse).getRayElectricity()
        elif sel in ("分线", "分纤", "交接箱", "光站", "放大器", "分支", "分配", "缆桥", "光机", "电源箱"):
            return JJX.JJX(sel, self.inse).getJJX()
        elif sel in ("井"):
            return Well.Well(sel, self.inse).getWell()
        elif sel in ("子管", "PE管", "pvc管", "pe管", "PVC管", "钢管", "出土管"):
            return PePvcTube.PePvcTube(sel, self.inse).getPePvcTube()
        elif sel in ("路面", "绿化", "人行道"):
            return RepairRoad.RepairRoad(sel, self.inse).getRepairRoad()
        elif sel in ("熔接", "台班", "用车", "用工"):
            return Welding.Welding(sel, self.inse).getWelding()

    # except:print(self.inse+"信息不全或格式有误")

    def decideall(self):
        s = self.select()
        x = re.split("\d*米$|一只|一套|\d*个$|\d*根$|\d*只$|\d*套$|\d*台$|\d*芯$|\d*D$|\d*平方米$|\d*平米$|\d*卷$|\d*次$", self.inse)[0]
        if s == "material":
            y = re.split('使用', x)[1]
            self.message = {"theType": 2, "material": y, "unit": self.theUnit()}  # 1只有工作量 2只有材料 3工作量材料都有 4增加GD49
        elif s in range(97, 139):
            self.message = {"theType": 4, "JSid": s, "unit": self.theUnit()}  # 所有窨井项
        elif s in range(5, 16) or s in range(24, 49) or s in (150, 151, 152, 155):
            self.message = {"theType": 3, "JSid": s, "material": x, "unit": self.theUnit()}  # 同时含有工作量和材料
        elif type(s) == int:
            self.message = {"theType": 1, "JSid": s, "material": "", "unit": self.theUnit()}  # 只有工作量

    def getDecide(self):
        self.decideall()
        return self.message
